var vm_zhuanjiabiandongdetail = new Vue({
	el : "#zhuanjiabiandongdetail",
	data : {
		deptid : $("#deptid").val(),		// 单位ID
		olddeptid : $("#olddeptid").val(),		// 单位ID
		piciid : "",//$("#piciid").val(),		// 专家变动批次ID
		zhanghuxinxi:{},//专家信息
		zhanghaoxinxiList:[],
		checkQuerenData: '0',

		isqushishow:false,

		biandonglist : [],// 专家变动列表custom
		qushilist:[], //去世list
		biandongid : '',//变动id
		biandong : {},//变动表

		shiwu : {},

		zhuanjialist : [],//本单位专家列表
		zhuanjianame : '',

		//编辑框单位下拉框
		zhuanzidanweilist : [],
		zhuanzhidanweilist : [],
		zhuanzidanweiname : '',
		zhuanzhidanweiname : '',


		shenhejilulist : [],

		//查询用字段
		zhuanjiamingcheng : '',
		biandongleixing : '',
		biandongriqi : '',

		qushi:{
			danweimingcheng: "",
			danweicengji: "",
			zhuanjiaxingming: "",
			gongzuodanwei: "",
			shifoubiandong: "",
			shifouchuli: "",
			chuliriqi: "",
		},

		biandong:{},
		shifoubiandong:"0",
		//

		editflag : '',//1添加 2修改


		pageindex : 1,		// 查询分页初始化页
		pagesize : 10,		// 查询分页初始化页面大小
		pageCount : 0,		// 总页数
		recordCount : 0,	// 总记录数
		targetpage : '', 	// 目标页
	},
	created : function(){
		var _this = this;
		$.post('/system/zhuanjiaqushiqueren/qushilist', {
			jigoudaima : _this.olddeptid,
			danweimingcheng: _this.qushi.danweimingcheng,
			danweicengji: _this.qushi.danweicengji,
			zhuanjiaxingming: _this.qushi.zhuanjiaxingming,
			gongzuodanwei: _this.qushi.gongzuodanwei,
			shifoubiandong: _this.qushi.shifoubiandong,
			shifouchuli: _this.qushi.shifouchuli,
			chuliriqi: _this.qushi.chuliriqi,
			pageindex: _this.pageindex,
			pagesize: _this.pagesize,
		}, function (ppData) {
			if (ppData.result == "1") {
				var data = ppData.resultContent;
				_this.qushilist = data.list;
				if(data.PageInfo.recordCount!=0)_this.isqushishow=true
				else _this.isqushishow=false
				if(_this.isqushishow==false) _this.bindBiandongList();
				var pageInfo = data.PageInfo;
				_this.pageindex = pageInfo.pageIndex;
				_this.pageCount = pageInfo.pageCount;
				_this.recordCount = pageInfo.recordCount;
				_this.targetpage = '';

			}
		}, "json");

		_this.checkQueren();

	},
	watch : {
		//监控分页情况，刷新列表
		pageindex : function(){
			if(_this.isqushishow==false) _this.bindBiandongList();
			else _this.bindQushiList()
		},

		pagesize : function(){
			if(_this.isqushishow==false) _this.bindBiandongList();
			else _this.bindQushiList()
		},
	},
	methods : {

		// 根据单位ID查询专家变动申请信息
		bindBiandongList : function(){
			var _this = this;

			var biandong_layer = layer.open({type:3});
			$.post('/system/zhuanjiabiandongdetail/custombiandonglist', {
				deptid : _this.deptid,
				zhuanjiamingcheng : _this.zhuanjiamingcheng,
				biandongleixing : _this.biandongleixing,
				biandongriqi : _this.biandongriqi,
				pageindex : _this.pageindex,
				pagesize : _this.pagesize,
				rdm : Math.random()
			},function(ppData) {
				layer.close(biandong_layer);

				if (ppData != null) {
					var data = ppData.resultContent;
					_this.biandonglist = data.biandonglist;

					var pageInfo = data.PageInfo;
					_this.pageindex = pageInfo.pageIndex;
					_this.pageCount = pageInfo.pageCount;
					_this.recordCount = pageInfo.recordCount;
					_this.targetpage = '';
				}
			},"json");
		},

		// 去世list
		bindQushiList : function(){
			var _this = this;
			$.post('/system/zhuanjiaqushiqueren/qushilist', {
				jigoudaima : _this.olddeptid,
				danweimingcheng: _this.qushi.danweimingcheng,
				danweicengji: _this.qushi.danweicengji,
				zhuanjiaxingming: _this.qushi.zhuanjiaxingming,
				gongzuodanwei: _this.qushi.gongzuodanwei,
				shifoubiandong: _this.qushi.shifoubiandong,
				shifouchuli: _this.qushi.shifouchuli,
				chuliriqi: _this.qushi.chuliriqi,
				pageindex: _this.pageindex,
				pagesize: _this.pagesize,
			}, function (ppData) {
				if (ppData.result == "1") {
					var data = ppData.resultContent;
					_this.qushilist = data.list;
					var pageInfo = data.PageInfo;
					_this.pageindex = pageInfo.pageIndex;
					_this.pageCount = pageInfo.pageCount;
					_this.recordCount = pageInfo.recordCount;
					_this.targetpage = '';

				}
			}, "json");
		},

		bindBiandong : function(){
			var _this = this;

			var biandong_layer = layer.open({type:3});
			$.post('/system/zhuanjiabiandongdetail/findone', {
				id : _this.biandongid,
				rdm : Math.random()
			},function(ppData) {
				layer.close(biandong_layer);

				if(ppData != null){

					if(ppData.result == "1"){
						var data = ppData.resultContent;
						_this.biandong = data;
						_this.biandong.id = _this.biandongid;
					}else{
						layer.alert(ppData.message);
					}
				}
			},"json");
		},

		toAdd:function(){
			var _this = this;

			$.ajaxSettings.async = false;
			//检查是否可以添加变动
			var result = "1"
			$.get('/system/jingfeipici/checkAdd', {
				deptid : _this.deptid,
				rdm : Math.random()
			},function(ppData) {
				if(ppData != null){
					result=ppData.result
					if(ppData.result == "0"){
						layer.alert(ppData.message);
					}
				}
			},"json");
			if(result=="0")return
			$.ajaxSettings.async = true
				$("#zhuanzidanwei_div").attr("style", "display:none");
				$("#zhuanzhidanwei_div").attr("style", "display:none");
				$("#myModalLabel").html("添加专家变动情况");
				$("#modal-dialog").attr("style", "width:1200px;");
				$("#biandongModal").modal();

				this.zhuanjianame = '';
				this.bindZhuanjiaList();

				this.biandong = {};
				this.editflag = 1;

		},

		//添加
		add:function(){
			var _this = this;
			if (_this.checkInputData()) {
				var biandong_layer = layer.open({type: 3});
				$.post('/system/zhuanjiabiandongdetail/save', {
					// biandongpiciid: _this.piciid,
					deptid : _this.deptid,
					zhuanjiaid : _this.biandong.zhuanjiaid,
					biandongleixing : _this.biandong.biandongleixing,
					biandongriqi : _this.biandong.biandongriqi,
					zhuanzidanwei : _this.biandong.zhuanzidanwei,
					zhuanzhidanwei : _this.biandong.zhuanzhidanwei,
					shuoming : _this.biandong.shuoming,
					rdm: Math.random()
				}, function (ppData) {
					layer.close(biandong_layer);
					if (ppData != null) {

						if (ppData.result == "1") {
							layer.open({
								time: 1000,
								btn: [],
								content: "添加成功!",
							});

							_this.refresh();
							$("#biandongModal").modal('hide');

						} else {
							layer.alert(ppData.message);
						}
					}
				}, "json");
			}
		},
		toLianxifangshi:function (zhuanjiaitem) {
			var _this = this;
			_this.zhanghuxinxi = zhuanjiaitem

			$.post('/system/deptdetail/Zhanghaoxinxi', {
				deptid: zhuanjiaitem.jigoudaima,
				rdm: Math.random()
			}, function (ppData) {
				if (ppData != null) {
					var data = ppData.resultContent;
					_this.zhanghaoxinxiList = data;
				}
			}, "json");

			$("#myModalLabel2").html("专家及相关层级经办人联系方式");
			$("#lianxifangshiModal").modal();
		},
		toModify:function(ppBiandongId){

			$("#zhuanzidanwei_div").attr("style","display:none");
			$("#zhuanzhidanwei_div").attr("style","display:none");
			$("#myModalLabel").html("修改专家变动信息");
			$("#modal-dialog").attr("style","width:1200px;");
			$("#biandongModal").modal();

			this.zhuanjianame = '';
			this.bindZhuanjiaList();

			this.biandongid = ppBiandongId;

			this.biandong = {};
			this.editflag = 2;
			// 绑定变动
			this.bindBiandong();
		},

		// 修改信息
		modify : function(){
			var _this = this;
			if (_this.checkInputData()) {
				var biandong_layer = layer.open({type: 3});
				$.post('/system/zhuanjiabiandongdetail/save', {
					id: _this.biandongid,
					zhuanjiaid : _this.biandong.zhuanjiaid,
					biandongleixing : _this.biandong.biandongleixing,
					biandongriqi : _this.biandong.biandongriqi,
					zhuanzidanwei : _this.biandong.zhuanzidanwei,
					zhuanzhidanwei : _this.biandong.zhuanzhidanwei,
					shuoming : _this.biandong.shuoming,
					rdm: Math.random()
				}, function (ppData) {
					layer.close(biandong_layer);
					if (ppData != null) {

						if (ppData.result == "1") {
							layer.open({
								time: 1000,
								btn: [],
								content: "修改成功!",
							});

							_this.refresh();
							$("#biandongModal").modal('hide');

						} else {
							layer.alert(ppData.message);
						}
					}
				}, "json");
			}
		},


		Delete:function(ppId){
			var _this = this;


			if (confirm("确定要删除吗？")) {
				var biandong_layer = layer.open({type:3});
				$.post('/system/zhuanjiabiandongdetail/deletebyid', {
					id: ppId,
					rdm: Math.random()
				}, function (ppData) {
					layer.close(biandong_layer);

					if (ppData != null) {

						if (ppData.result == "1") {
							layer.open({
								time: 1000,
								btn: [],
								content: "删除成功!",
							});

							_this.refresh();
						} else {
							layer.alert(ppData.message);
						}
					}
				}, "json");
			}
		},

		//检查项目数据
		checkInputData : function() {
			if (!$.trim(this.biandong.zhuanjiaid)) {
				layer.alert("请选择变动的专家！");
				return false;
			}

			if (!$.trim(this.biandong.biandongleixing)) {
				layer.alert("请选择变动的类型");
				return false;
			}

			return true;
		},

		getDate:function(){
			var _this = this;

			_this.biandong.biandongriqi=$("#biandongriqi").val();
		},
		getDate_chuliriqi: function () {
			var _this = this;

			_this.chuliriqi = $("#chuliriqi").val();
		},

		getDate_chaxun:function(){
			var _this = this;

			_this.biandongriqi=$("#biandongriqi_chaxun").val();
		},

		refresh:function(){
			var _this = this;
			_this.zhuanjiamingcheng = '',
				_this.biandongleixing = '',
				_this.biandongriqi = '',

				_this.qushi={
				danweimingcheng: "",
					danweicengji: "",
					zhuanjiaxingming: "",
					gongzuodanwei: "",
					shifoubiandong: "",
					shifouchuli: "",
					chuliriqi: "",
			}
			if(_this.isqushishow==false) _this.bindBiandongList();
			else _this.bindQushiList()
		},

		bindZhuanjiaList : function(){
			var _this = this;

			var biandong_layer = layer.open({type:3});
			$.post('/system/deptzhuanjia/find_by_deptid', {
				deptid : _this.deptid,
				zhuanjianame : _this.zhuanjianame,
				rdm : Math.random()
			},function(ppData) {
				layer.close(biandong_layer);

				if (ppData != null) {
					var data = ppData;
					_this.zhuanjialist = data;
				}
			},"json");
		},

		Submit:function(ppId){
			var _this = this;


			if (confirm("确定要提交吗？")) {
				var biandong_layer = layer.open({type:3});
				$.post('/system/renwu/submit_custom', {
					id: ppId,
					deptid: _this.deptid,
					rdm: Math.random()
				}, function (ppData) {
					layer.close(biandong_layer);

					if (ppData != null) {
						if (ppData.result == 1) {
							layer.open({
								time: 2000,
								btn: [],
								content: "提交成功",
							});

							location.reload();
						} else {
							layer.alert(ppData.message);
						}
					}
				}, "json");
			}
		},

		wubiandongqueren:function(){
			var _this = this;


			if (confirm("是否确认本批专家变动？")) {

				var biandong_layer = layer.open({type:3});
				$.post('/system/queren/queren', {
					deptid: _this.deptid,
					rdm: Math.random()
				}, function (ppData) {
					layer.close(biandong_layer);

					if (ppData != null) {
						if (ppData.result == 1) {
							layer.alert("提交成功");
							_this.refresh();
						} else {
							layer.alert(ppData.message);
						}
					}
				}, "json");
			}
		},

		showShenhejiluModel:function(ppShiwuId){
			var _this = this;

			$("#shenhejiluModalLabel").html("审核进度");
			$("#shenhejiluModal").modal();

			_this.bindShenhejilu(ppShiwuId);
		},

		bindShenhejilu:function(ppShiwuId){
			var _this = this;

			var biandong_layer = layer.open({type:3});
			$.post('/system/renwu/findshenhejilu', {
				shiwuid : ppShiwuId,
				rdm : Math.random()
			},function(ppData) {
				layer.close(biandong_layer);

				if (ppData != null) {
					var data = ppData;
					_this.shenhejilulist = data.resultContent;
				}
			},"json");
		},

		//空壳
		bindZhuanzidanweiList :function (){

		},
		bindZhuanzhidanweiList :function (){

		},

		checkQueren:function(){
			var _this = this;

			var biandong_layer = layer.open({type:3});
			$.post('/system/queren/checkqueren', {
				deptid : _this.deptid,
				rdm : Math.random()
			},function(ppData) {
				layer.close(biandong_layer);

				if (ppData != null) {
					var data = ppData;
					_this.checkQuerenData = data.resultContent;
				}
			},"json");
		},

		//首页
		firstPage : function(){
			this.pageindex = 1;
		},
		//尾页
		lastPage : function(){
			this.pageindex = this.pageCount;
		},
		//上一页
		prePage : function(){
			var prePage = ((this.pageindex -1) <= 0) ? 1 : (this.pageindex -1);
			this.pageindex = prePage;
		},
		//下一页
		nextPage : function(){
			var nextPage = ((this.pageindex +1) >= this.pageCount) ? this.pageCount : (this.pageindex +1);
			this.pageindex = nextPage;
		},
		//跳到目标页
		targetPage : function() {
			if( this.targetpage != '' && this.targetpage <= this.pageCount && this.targetpage > 0){
				this.pageindex = this.targetpage;
				this.targetpage = '';
			}
		},

	},
})